//
//  StaffListCell.m
//  LogisticsSupplier
//
//  Created by 吕晶 on 2020/8/31.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "StaffListCell.h"

@interface StaffListCell ()

@property (nonatomic, strong) UIImageView *iconImgView;
@property (nonatomic, strong) UILabel *nameLab;
@property (nonatomic, strong) UILabel *timeLab;
@property (nonatomic, strong) UIImageView *arrowImgView;

@end

@implementation StaffListCell

+ (instancetype)StaffListCellWithTableView:(UITableView *)tableView {
    static NSString *cellID = @"StaffListCell";
    StaffListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[StaffListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = HexColor(0xffffff);
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.iconImgView = [[UIImageView alloc] initWithFrame:CGRectMake(15, 20, 50, 50)];
        self.iconImgView.backgroundColor = Color_backgroundColor;
        self.iconImgView.layer.masksToBounds = YES;
        self.iconImgView.layer.cornerRadius = 25;
        self.iconImgView.contentMode = UIViewContentModeScaleAspectFill;
        [self.contentView addSubview:self.iconImgView];
        
        self.arrowImgView = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenW - 15 - 24, self.iconImgView.nim_top + (50 - 24) * 0.5, 24, 24)];
        self.arrowImgView.image = [UIImage imageNamed:@"icon_staff_list_arrow"];
        [self.contentView addSubview:self.arrowImgView];
        
        self.nameLab = [[UILabel alloc] initWithFrame:CGRectMake(self.iconImgView.nim_right + 10, self.iconImgView.nim_top + 5, self.arrowImgView.nim_left - (self.iconImgView.nim_right + 10), 17)];
        self.nameLab.font = BoldFontOfSize(17);
        self.nameLab.textColor = HexColor(0x2B2C44);
        [self.contentView addSubview:self.nameLab];
        
        self.timeLab = [[UILabel alloc] initWithFrame:CGRectMake(self.nameLab.nim_left, self.iconImgView.nim_bottom - 13 - 5, self.nameLab.nim_width, 13)];
        self.timeLab.font = [UIFont systemFontOfSize:12];
        self.timeLab.textColor = HexColor(0x9C9DB3);
        [self.contentView addSubview:self.timeLab];
        
        self.height = self.iconImgView.nim_bottom + 20;
    }
    return self;
}

-(void)setModel:(StaffMainModel *)model {
    _model = model;
    [self.iconImgView sd_setImageWithURL:[NSURL URLWithString:model.headimg]];
    NSMutableString *str = [NSMutableString string];
    if (model.department.length) {
        [str appendFormat:@"%@",model.department];
    }
    if (model.username.length) {
        if (str.length) {
            [str appendFormat:@"-%@",model.username];
        }else {
            [str appendFormat:@"%@",model.username];
        }
    }
    self.nameLab.text = str;
    self.timeLab.text = [NSString stringWithFormat:@"更新时间：%@",model.updatetime];
    if ([model.isadmin isEqualToString:@"1"]) {
        self.arrowImgView.hidden = YES;
    }else {
        self.arrowImgView.hidden = NO;
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
